home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-27 | 1.9 KB | 79 lines | [TEXT/KAHL] |
- //----------------------------------------------------------------------------------
- // File : dynMenu.c
- // Date : Dec 28, 1994
- // Author : Jim Stout
- // :
- // Purpose : Example code for implementing a dynamic popup menu
- //----------------------------------------------------------------------------------
- #include "movableModal.h"
- #include "demoDialog.h"
-
- static void buildMenu(MenuHandle mHdl, short type);
-
- extern void dynMenu()
- {
- DialogPtr theDialog;
- short itemHit,inx,t;
- Rect r;
- Handle h;
- MenuHandle mHdl;
-
- // must create menu before control (which is created by the dialog)
-
- mHdl = NewMenu(210, "\p");
- buildMenu(mHdl, 4);
- InsertMenu(mHdl, -1);
-
- // create the dialog
-
- theDialog = GetNewDialog(210,0L,(DialogPtr)-1);
- if(theDialog) {
-
- SetPort(theDialog);
-
- GetDItem(theDialog, 4, &t, &h, &r); // set radio button
- SetCtlValue((ControlHandle)h, 1);
-
- ShowWindow(theDialog);
-
- do {
- movableModalDialog(nil,&itemHit);
- switch(itemHit) {
- case 4:
- case 5:
- case 6:
- for(inx=4;inx<7;inx++) {
- GetDItem(theDialog, inx, &t, &h, &r); // toggle radio btn
- if(inx == itemHit)
- SetCtlValue((ControlHandle)h, 1);
- else
- SetCtlValue((ControlHandle)h, 0);
-
- buildMenu(mHdl, itemHit); // change menu items
- GetDItem(theDialog, 3, &t, &h, &r);
- SetCtlValue((ControlHandle)h, 1); // reset control value
- Draw1Control((ControlHandle)h); // force it to redraw
- }
- break;
- }
- }while(itemHit != 1 && itemHit != 2);
- DisposDialog(theDialog);
- DeleteMenu(210);
- DisposeMenu(mHdl);
- }
- }
-
- static void buildMenu(MenuHandle mHdl, short type)
- {
- short inx,max;
- Str255 s;
-
- max = CountMItems(mHdl);
- for(inx=1;inx<=max;inx++) // remove existing menu items
- DelMenuItem(mHdl, 1);
- max = 6;
- for(inx=1;inx<=max;inx++) { // add new items to menu
- GetIndString(s,206+type, inx);
- AppendMenu(mHdl, s);
- }
- }